/**
 *  easyUI验证扩展，增加自定义验证2014-5-29 15:16:07
 * 
 * 使用方法: 单个验证: data-options="validType:'minLength[5]'"  或者  data-options="[validType:'minLength[5]']" 
 *			 多个验证: data-options="validType:['isNull','unsafe','minLength[5]']"
 * 
 * @param {Object} value
 * @param {Object} param
 * @return {TypeName} 
 */
$.extend($.fn.validatebox.defaults.rules, {
	isNull: { // 非空判断，主要是针对输入空格的验证
		validator: function(value, param){
			if(value.indexOf(' ') != -1){
				return false;
			}
			return true;
		},
		message: '该项不能输入空格'
	},
	airportCode: { // 验证机场三字码为大写英文字母
		validator: function(value,param){
			return /^[A-Z]+$/.test(value);
		},
		message: '请输入大写英文字母'
	},
	minLength: { // 最小长度验证  使用：data-options="validType:['minLength[3]']"
		validator: function(value, param){
			return value.length >= param[0];
		},
		message: '不能少于{0}个字符'
	},
	maxLength: { // 最大长度验证  使用：data-options="validType:['maxLength[10]']"
		validator: function(value, param){
			return value.length <= param[0];
		},
		message: '不能超过{0}个字符'
	},
	unsafe: { // 非法字符验证
		validator: function(value, param){
			return !/[\\\/:\*#$\?？\<\>\|\^%\@\~\￥\{\}\(\),\'‘’“”，。\+\、《》；：！（）;.!&\"]/.test(value);
		},
		message: '该项不能输入非法字符'
	},
	uneasysafe: { // 简单非法字符验证
		validator: function(value, param){
			return !/[\\\/:\*#$\?？\<\>\|\^%\@\~\￥\{\}\(\)\'‘’“”。\+\《》；：！（）;.!&\"]/.test(value);
		},
		message: '该项不能输入非法字符'
	},
	number:{//数字 add by lif
		validator: function(value, param){
			return /^\d+$/.test(value);
		},
		message: '请输入正确的数字'
	},
	isIp:{// add by shenb
		validator: function(value, param){
			return /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(value);
		},
		message: '请输入正确的IP'
	},
	unique: {    
	        validator: function(value,param){
	        	if(param[3] == undefined){
	        		param[3]='';
	        		if(opBusseness != undefined){
	        			oldValue = '';
	        			oldResult = true;
	        			opBusseness = undefined;
	        		}
	        	}else{
	        		if(opBusseness != param[3]){
	        			oldValue = '';
	        			oldResult = true;
	        			opBusseness = param[3];
	        		}
	        	}
	        	value = encodeURI(encodeURI(value.replace(/\+/g," "),true));
	        	var result = oldResult;
	        	if($.trim(value) != '' && $.trim(value) != oldValue){
	        		$.ajax({
						type: "get",
						async:false,
						url:  param[0]+"/validate/unique",
						data:'tableName='+param[1]+'&field='+param[2]+'&value='+value+'&id='+param[3],
						success: function(data){
							if(data == "success"){
								result = true;
							}else {
								result = false;
							}
						}
					});
	        	}
	        	oldValue = $.trim(value);
	        	oldResult = result;
				return result;
	        },    
	        message: '命名重复，请重新命名'   
	    },
	email:{// add by wangb
		validator: function(value, param){
			return /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(value);
		},
		message: '请输入正确的邮箱'
	},
	date:{// add by fengya
		validator: function(value, param){
			return /\d{4}-((0[1-9])|(1[0-2]))-((0[1-9])|([1-2]\d)|(3[0-1]))$/.test(value);
		},
		message: '请输入正确格式的日期'
	},
	card:{// add by fengya
		validator: function(value, param){
			return /(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(value);
		},
		message: '请输入正确格式的身份证号码'
	},
	charAndDigit:{// add by fengya
		validator: function(value, param){
			return /(^[a-zA-Z0-9]+$)/.test(value);
		},
		message: '该项只能输入字母和数字'
	},
	phone:{// add by wangb
		validator: function(value, param){
			return /^((\(\d{2,3}\))|(\d{3}))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/.test(value);
		},
		message: '请输入正确的电话号码'
	},
	mobile:{// add by wangb
		validator: function(value, param){
			return /^1[3|4|5|7|8][0-9]\d{8}$/.test(value);
		},
		message: '请输入正确的手机号'
	},
	maxNumber:{ // add by zhoulh 用于绩效考核-评分管理-验证分数最大值
		validator: function(value, param){
			return value <= param[0];
		},
		message: '输入值不能大于：{0}'
	},
	minNumber:{ // add by zhoulh 用于绩效考核-评分管理-验证分数最大值
		validator: function(value, param){
			return value >= param[0];
		},
		message: '输入值不能小于：{0}'
	},
	
	max: { //用法validType="max['fxpgtjbId']" add by wangb 开始值小于结束值
			validator: function(value,param){
			return parseInt(value) < parseInt($(document.getElementById(param[0])).val())
			},
			message: '开始值必须小于结束值'
		},
	min: { //用法validType="min['fxpgtjbId']" add by wangb 结束值大于开始值
			validator: function(value,param){
			return parseInt(value) > parseInt($(document.getElementById(param[0])).val())
			},
			message: '结束值必须大于开始值'
		},
	maxDate: { 
		validator: function(value,param){
			var dateValue = $.trim(value);
			if(dateValue != '' && param[0] != ''){
				var datestr = dateValue.replace(/-/g,"/");
				var date = new Date(datestr);
				return date.getTime()<param[0];
			}
			return false;
		},
		message: '时间不能大于当前时间'
	},
	minDate: { 
		validator: function(value,param){
			var dateValue = $.trim(value);
			if(dateValue != '' && param[0] != ''){
				var datestr = dateValue.replace(/-/g,"/");
				var date = new Date(datestr);
				return date.getTime()>param[0];
			}
			return false;
		},
		message: '时间不能小于当前时间'
	},
	validateNum:{ // add by zhoulh 小数位数验证，只能输入一位小数
		validator: function(value, param){
			return /^(\d+\.\d{1,1}|\d+)$/.test(value);
		},
		message: '请输入符合规则且小数位数为一位的数字'
	},
	priceDecimal:{ // 两位有效数字的double
		validator: function(value, param){
			return /^(\d+\.\d{1,2}|\d+)$/.test(value);
		},
		message: '请输入符合规则且小数位数为两位的数字'
	},
	validateAffirmPassword:{ // add by chirq 验证两次密码是否一致是否相等
		validator: function(value, param){
			return value == $('#'+param[0]).val();
		},
		message: '确认密码与新密码不一致'
	},
	chineseChar:{ // add by wangdingchun 中文类型
		validator: function(value){
			return /^[\u4e00-\u9fa5]+$/.test(value);
		},
		message: '必须为中文格式'
	},
	goodsBrand:{ // add by zhn 品牌只允许输入汉字
		validator: function(value){
			return /^[\u4e00-\u9fa5]+$/.test(value);
		},
		message: '品牌只允许输入汉字'
	},
	goodsNum:{ // add by zhn 型号不允许输入汉字
		validator: function(value){
		    return /^[a-zA-Z0-9\-]+$/.test(value); 
	    },
		message: '型号只允许输入字母、数字、中划线（-）'
	},
	describe:{ // add by wangdingchun  描述、备注等要求的格式
		validator: function(value){
			return /^[\u4e00-\u9fa5A-Za-z\d\s'"]+$/.test(value);
		},
		message: '存在非法字符'
	},
	length:{ // add by wangdingchun  长度最小值和最大值
    	validator:function(value,param){
        var len=$.trim(value).length;
            return len>=param[0]&&len<=param[1];
        },
            message:"内容长度介于{0}和{1}之间."
    },
    defalutSelect:{
    	validator:function(value){
    		if(value=="请选择")
    			return false;
    		else
    			return true;
    	},
    		message:"该项值不能为空或默认值"
    },
    digitalFormat:{ //add by cuixing  验证分数必须为0.5倍数
    	validator:function(value){
    		return /(^[0-9]*[1-9][0-9]*$)/.test(value*2);
    	},
    		message:"分数必须为0.5的倍数"
    },
    positiveInteger:{ //add by cuixing  验证数字必须为正整数
    	validator:function(value){
    		return /(^[1-9]+[0-9]*$)/.test(value);
    	},
    		message:"必须为大于0的整数"
    },
    textVerification:{
    	validator:function(value){ //add by cuixing  文本必须为中文、英文、数字
    		return /(^[\u4e00-\u9fa5a-zA-Z0-9]+$)/.test(value);
    	},
    		message:"必须为中文、英文、数字"
    },
    dateTimeMoreCompare: { // add by fengya  日期比较(yyyy-MM-dd格式比较)
		validator: function(value,param){
			var beginTime = $.trim($('#'+param[0]).datetimebox('getValue'));
			if($.trim(beginTime)!=''){
				var beginDate = new Date(beginTime.replace(/-/g,"/"));
				var endDate = new Date($.trim(value).replace(/-/g,"/"));
				return endDate.getTime() >= beginDate.getTime();
			}
			return true;
		},
		message: '结束时间不能小于开始时间'
	},
    dateTimeLessCompare: { // add by fengya  日期比较(yyyy-MM-dd格式比较)
			validator: function(value,param){
				var endDate = $.trim($('#'+param[0]).datetimebox('getValue'));
				if($.trim(endDate)!=''){
					var endDate = new Date(endDate.replace(/-/g,"/"));
					var beginDate = new Date($.trim(value).replace(/-/g,"/"));
					return endDate.getTime() >= beginDate.getTime();
				}
				return true;
			},
			message: '开始时间不能大于结束时间'
		},
	rangeMoreCompare:{
		validator:function(value,param){
			var startValue = $.trim($('#'+param[0]).val()) - 0;
			if(startValue){
				return (value - 0) >= startValue;
			}
			return true;
		},
		message: "结束值不能小于开始值"
	},
	rangeLessCompare:{
		validator:function(value,param){
			var endValue = $.trim($('#'+param[0]).val()) - 0;
			if(endValue){
				return endValue >= (value - 0);
			}
			return true;
		},
		message: "开始值不能大于结束值"
	},
     isBlank: {
         validator: function (value, param) {value=$.trim(value); return $.trim(value) != '' },
         message: '不能为空，全空格也不行'
     },
     isOpenBidPro: {    
	        validator: function(value,param){
	        	//value = encodeURI(encodeURI(value.replace(/\+/g," "),true));
	        	var bidStartDateStr=$("input[name='bidStartDateStr']").val();
	        	//bidStartDateStr="2016-12-2 11:30:47";
	        	if(bidStartDateStr==""){
	        		return false;
	        	}
	        	var time=top.$("#bidStartTimeStr").val();
	        	//bidStartDateStr=$("#bidStartDateStr").datebox("getValue");
	        	var tempDate = new Date(Date.parse(bidStartDateStr.replace(/-/g,"/")));
//	        	var y = tempDate.getFullYear();  
//	 		    var m = tempDate.getMonth()+1;  
//	 		    var d = tempDate.getDate();  
	        	var temp = (bidStartDateStr.split('-'));  
	 		    var y = parseInt(temp[0],10);  
	 		    var m = parseInt(temp[1],10);  
	 		    var d = parseInt(temp[2],10);  
	 		    var date=y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d)+" "+value +":00:00";
	 		    
	 		    
	        	if($.trim(value) != ''){
	        		$.ajax({
						type: "get",
						async:false,
						url:  param[0]+"/business/projectmanage/bidDateVerify",
						data:'date='+date,
						success: function(data){
							result=data;
						}
					});
	        	}
				return result;
	        },    
	        message: '当前时间点已有{1}个项目开标'
	    },
	    // isWorkDay: {
	    //     validator: function(value,param){
	    //     	var validTime=$("input[name='validTime']").val();//确认时间
	    //     	var bidStartDateStr=$("input[name='bidStartDateStr']").val();
	    //     	if(bidStartDateStr==""){
	    //     		return false;
	    //     	}
	    //     	var time=top.$("#bidStartTimeStr").val();
	    //     	var temp = (bidStartDateStr.split('-'));
	 	// 	    var y = parseInt(temp[0],10);
	 	// 	    var m = parseInt(temp[1],10);
	 	// 	    var d = parseInt(temp[2],10);
	 	//
	 	// 	    var date=y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d)+" "+value +":00:00";
	 	//
	 	// 	    var url=param[0]+"/business/projectmanage/isWorkDay";
	 	//
	    //     	if($.trim(value) != ''){
	    //     		$.ajax({
			// 			type: "get",
			// 			async:false,
			// 			url:  url,
			// 			data:'date='+date+"&validTime="+validTime,
			// 			success: function(data){
			// 				result=data;
			// 			}
			// 		});
	    //     	}
			// 	return result;
	    //     },
	    //     message: '非工作日不允许设置项目开标,且确认截止时间与开标时间需间隔3个工作日以上'
	    // },
	    isWorkDayToShot: {
	        validator: function(value,param){
	        	var validTime=$("input[name='validTime']").val();//确认时间
	        	var bidStartDateStr=$("input[name='bidStartDateStr']").val();
	        	if(bidStartDateStr==""){
	        		return false;
	        	}
	        	var time=top.$("#bidStartTimeStr").val();
	        	var temp = (bidStartDateStr.split('-'));  
	 		    var y = parseInt(temp[0],10);  
	 		    var m = parseInt(temp[1],10);  
	 		    var d = parseInt(temp[2],10);  
	 		    
	 		    var date=y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d)+" "+value +":00:00";
	 		    
	 		    var url=param[0]+"/business/projectmanage/isWorkDayToShot"
	        	if($.trim(value) != ''){
	        		$.ajax({
						type: "get",
						async:false,
						url:  url,
						data:'date='+date+"&validTime="+validTime,
						success: function(data){
							result=data;
						}
					});
	        	}
				return result;
	        },    
	        message: '非工作日不允许设置项目开标'   
	    },
	    comboSelect: {
	        validator: function (value,param) {//param为默认值
	            return value !=param[0];
	        },
	        message: '请选择'
	    },
	    isWorkDayToValidTime: {    
	        validator: function(value,param){
	        	var validTime=$("input[name='validTime']").val();//确认时间
	        	var result;
	        	if($.trim(value) != ''){
	        		$.ajax({
						type: "get",
						async:false,
						url:  url=param[0]+"/business/projectmanage/isWorkDayToShot",
						data:'date='+validTime,
						success: function(data){
							result=data;
						}
					});
	        	}
				return result;
	        },    
	        message: '非工作日不允许设置确认时间'   
	    },
	    validProjName: {
	        validator: function(value,param){
	        	var result;
	        	if($.trim(value) != ''){
	        		$.ajax({
						type: "post",
						async:false,
						url:  url=param[0]+"/auction/business/buyer/validProjName",
						data:'auctionName='+value,
						success: function(data){
							result=data;
						}
					});
	        	}
				return result;
	        },    
	        message: '您在30天前内已经创建此名称的项目了!'   
	    },
	    isWorkDayToDate: {
  	        validator: function(value,param){
  	        	var result;
  	 		    var url=url=param[0]+"/business/projectmanage/isWorkDayToShot"
  	        	if($.trim(value) != ''){
  	        		$.ajax({
  						type: "get",
  						async:false,
  						url:  url,
  						data:'date='+value+' 00:00:00',
  						success: function(data){
  							result=data;
  						}
  					});
  	        	}
  				return result;
  	        },    
  	        message: '非工作日不允许设置'   
  	    },
		afterAuditTime: {
			 validator: function (value, param) {
				 var beginDate = $.trim($('#'+param[0]).datetimebox('getValue'));
				 if($.trim(beginDate)!=''){
					 var beginDate = new Date(beginDate.replace(/-/g,"/"));
					 var endDate = new Date($.trim(value).replace(/-/g,"/"));
					 return endDate.getTime() > beginDate.getTime();
				 }
				return true;;
			 },
			 message: '后审时间不能早于报价截止时间'
		 },
	    isWorkDayToNewBidStartTime: {    
	        validator: function(value,param){
	        	var validTime=$("input[name='bidStartDateStr']").val();
	        	var temp = (validTime.split('-'));  
	 		    var y = parseInt(temp[0],10);  
	 		    var m = parseInt(temp[1],10);  
	 		    var d = parseInt(temp[2],10);  
	 		    
	 		    var date=y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d)+" "+value +":00:00";
	        	var result;
	        	if($.trim(value) != ''){
	        		$.ajax({
						type: "get",
						async:false,
						url:url=param[0]+"/business/projectmanage/isWorkDayToShot",
						data:'date='+date,
						success: function(data){
							result=data;
						}
					});
	        	}
				return result;
	        },    
	        message: '非工作日不允许设置确认时间'   
	    },
        isOkWorkDay: {
            validator: function(value,param){
                //开始时间
                var startDate=new Date().pattern("yyyy-MM-dd")+" 00:00:00";

                //结束时间
                var temp = (value.split('-'));
                var y = parseInt(temp[0],10);
                var m = parseInt(temp[1],10);
                var d = parseInt(temp[2],10);
                var endDate=y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d)+" 23:59:59";

                var url=param[0]+"/business/projectmanage/isOkWorkDay";
                var result;
                if($.trim(value) != ''){
                    $.ajax({
                        type: "get",
                        async:false,
                        url:  url,
                        data:'endTime='+endDate+"&startDate="+startDate,
                        success: function(data){
                            result=data;
                        }
                    });
                }
                return result;
            },
            message: '非工作日不允许设置,且当前时间与公示结束时间需间隔{1}个工作日以上'
        },
        isNotZero: { // 非空判断，主要是针对输入空格的验证
		validator: function(value, param){
			if(value== 0){
				return false;
			}
			return true;
		},
		message: '加价不能为0元'
	},
	 isWorkDayJ: {  //间隔工作日(竞价公示)
	        validator: function(value,param){
	        	var bidStartDateStr=$("input[name='bidStartDateStr']").val();
	        	var bidStartTimeStr=$("input[name='bidStartTimeStr']").val();
	        	if(bidStartDateStr==""){
	        		return false;
	        	}
	 		    var date=value+" "+bidStartTimeStr+":00:00";
	 		    var url=param[0]+"/auctionBid/business/isWorkDayJ";
	        	if($.trim(value) != ''){
	        		$.ajax({
						type: "get",
						async:false,
						url:  url,
						data:'date='+date,
						success: function(data){
							result=data;
						}
					});
	        	}
				return result;
	        },
	        message: "非工作日不允许设置项目开标,重启时间与开标时间需间隔{1}个工作日以上"
	    },

	 isWorkDayZ: {  //间隔工作日（中标公示）
	        validator: function(value,param){
	        	debugger;
	        	var hitShowEndString=$("input[name='hitShowEndString']").val();
	        	if(hitShowEndString==""){
	        		return false;
	        	}
	 		    var date=value+" 00:00:00";
	 		    var url=param[0]+"/auctionBid/business/isWorkDayZ";
	        	if($.trim(value) != ''){
	        		$.ajax({
						type: "get",
						async:false,
						url:  url,
						data:'date='+date,
						success: function(data){
							result=data;
						}
					});
	        	}
				return result;
	        },
	        message: "非工作日不允许设置项目开标,重启时间与中标公示结束时间需间隔{1}个工作日以上"
	    },

     isWorkDayAuction: {  //间隔工作日（中标公示）
	        validator: function(value,param){
	        	var hitShowEndString=$("input[name='hitShowEndString']").val();
	        	if(hitShowEndString==""){
	        		return false;
	        	}
	 		    var date=value+" 00:00:00";
	 		    var url=param[0]+"/auctionBid/business/isWorkDayAuction";
	        	if($.trim(value) != ''){
	        		$.ajax({
						type: "get",
						async:false,
						url:  url,
						data:'date='+date,
						success: function(data){
							result=data;
						}
					});
	        	}
				return result;
	        },
	        message: "非工作日不允许设置项目开标,竞拍开始时间与当前时间间隔{1}个工作日以上"
	    },
	isMaxPrice: {  //不大于限额
		validator: function(value,param){
			var catagoryId = $("#catagoryId").combobox("getValue") ;
			var url=param[0]+"/auction/business/isMaxPrice";
				$.ajax({
					type: "get",
					async:false,
					url:  url,
					data:{catagoryId:catagoryId,maxprice:value},
					success: function(data){
						result=data;
					}
				});

			return result;
		},
		message: "超出该类型项目的竞拍限额！"
	},

	isMonAm:{
		           validator: function (value, param) {
		           	debugger;
					var bidStartDateStr=$("input[name='bidStartDateStr']").val();
					var endDate = new Date(bidStartDateStr.replace(/-/g,"/"));
					if(endDate.getDay()==1&&value==09){//开标时间校验（不能为星期一）
						return false;
					}
					return true;
				 },
				 message: '开标时间不能为星期一上午'
			 },

	  isNotZeroDeposit: { // '保证金不能为0元'
		validator: function(value, param){
			if(value== 0){
				return false;
			}
			return true;
		},
		message: '保证金不能为0元'
	}
});
var oldValue = '';
var oldResult = true;
var opBusseness;
var message='';